package com.example.shuiyin.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.OncePerRequestFilter;

import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Configuration
public class FilterDisableConfig {

    /**
     * 禁用可能已经注册的JWT过滤器
     */
    @Bean
    public FilterRegistrationBean<Filter> disableJwtFilter() {
        FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new Filter() {
            @Override
            public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
                    throws IOException, ServletException {
                chain.doFilter(request, response);
            }
        });
        
        // 设置高优先级，但不会被使用，因为我们设置了enabled=false
        registration.setOrder(-101);
        registration.setEnabled(false);
        registration.addUrlPatterns("/*");
        registration.setName("disabledJwtFilter");
        
        return registration;
    }
} 